<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Registrar extends MY_Controller {

	function __construct()
	{
		parent::__construct();
		$this->page_auth->secure_page('registrar');
		$this->load->model(array('M_school_years','M_enrollees','M_users','M_news_and_events','M_search','M_levels','M_for_enrollment_id'));
		$this->load->library(array('form_validation'));
		$this->load->helper(array('url','form'));
		$this->current_user = $this->session->userdata('username').' - '.$this->session->userdata('userType');
		$this->_init_pagnate_config();
		$this->view_data['r_url'] = str_replace('/','-',uri_string());
	}
	
	function index()
	{
		$this->view_data['system_message'] = $this->_msg();
	}
	
	/*
	 * Custom search for registrar
	 * Search all verified_enrollees (verified through email verification)
	*/
	
	public function international_students()
	{
		if($this->input->post('search'))
		{
			$search_items = (object)$this->input->post('search_string_item');
			$this->view_data['students'] = $this->M_search->search_international_students($search_items);
			$this->view_data['links'] =NULL;
			
		}else{
			$this->load->library('pagination');
			$this->pagnate_config['base_url'] = base_url().'registrar/international_students';
			$this->pagnate_config['per_page'] = 30;
			$this->pagnate_config["uri_segment"] = 3;
			$this->pagnate_config['total_rows'] = $this->M_search->count_international_students();
			
			$this->pagination->initialize($this->pagnate_config);
			
			$page = ($this->uri->segment(3)) ? $this->uri->segment(3) : 0;
			$this->view_data['students'] = 	$this->M_search->international_students($this->pagnate_config['per_page'],$page);
			
			$this->view_data['links'] = $this->pagination->create_links();
			
		}
		
		$this->view_data['levels'] = $this->M_levels->get_all_levels_array();		
	}
	
	function add_room()
	{
		$this->view_data['auth'] = $this->authlink-> generate_authlink();
		if($this->uri->segment(3) == 'success' && $this->uri->segment(4) != '')
			$this->view_data['system_message'] = 'Room '.$this->uri->segment(4).' added successfully!';
		if($this->uri->segment(3) == 'failed')
			$this->view_data['system_message'] = 'Ooops, something went wrong please try again later.';
		if($this->uri->segment(3) == 'successrfaile')
			$this->view_data['system_message'] = 'Section Room added But failed to update section status';
		
		$this->view_data['sections'] = $this->M_sections->get_all_sections();
		if($this->input->post('add')){

			#$this->form_validation->set_rules('level_id', 'Room Assignment', 'required');
			$this->form_validation->set_rules('section_id', 'Section Assignment', 'required');
			$this->form_validation->set_rules('name', 'Room Name', 'required');
			$this->form_validation->set_rules('description', 'Room Description', 'required');
			
			if($this->form_validation->run() == FALSE){
				$this->view_data['system_message'] = validation_errors();
			}else
			{
				$this->load->model('M_rooms');
				$v = (object) $this->input->post();
				$room_data['name'] = $v->name;
				$room_data['description'] = $v->description;
				$room_data['section_id'] = $v->section_id;
				$room_data['created'] = NOW;
				$room_data['created_by'] = $this->session_user;
				if($this->M_rooms->add_room($room_data) == TRUE)
				{
					if($this->M_sections->set_sections_room_assigned($v->section_id))
					{
						if($this->M_sections->update_section_room_assigned_status($v->section_id))
						{
							redirect('admin/add_room/success/'.$v->name);
						}else{
							redirect('admin/add_room/successrfaile/'.$v->name);
						}
					}else
					{
						redirect('admin/add_room/failed');
					}
				}else
				{
					redirect('admin/add_room/failed');
				}
			}
		}
	}
	
	public function add_schedule($section_id = FALSE)
	{
		if($section_id !== FALSE AND is_numeric($section_id))
		{
			$section_id = intval($section_id);
			$this->view_data['system_message'] = $this->session->flashdata('system_message');
			$this->load->model(array('M_schedule','M_sections','M_employees'));
			$this->view_data['subjects'] = $this->M_schedule->get_subjects_for_section_and_grade_level($section_id);
			$this->view_data['section_profile'] = $this->M_sections->get_section($section_id);
			$this->view_data['teachers'] = $this->M_employees->get_all_employees_array('teacher');
			$this->view_data['section_id'] = $section_id;
			$this->view_data['schedules'] = $this->M_schedule->get_all_schedule_by_section($section_id);
			
			
			if($this->input->post('add_schedule'))
			{
				$this->form_validation->set_rules('subject_id','Subject','required');
				$this->form_validation->set_rules('t_s','Time Start','required');
				$this->form_validation->set_rules('t_e','Time End','required');
				$this->form_validation->set_rules('days','Days','required');
				$this->form_validation->set_rules('teacher','Teacher In-Charge','required');
				
				if($this->form_validation->run() !== FALSE)
				{
					$input['subject_id'] = $this->input->post('subject_id',TRUE);
					$input['time_from'] = $this->input->post('t_s',TRUE);
					$input['time_to'] = $this->input->post('t_e',TRUE);
					$input['day'] = $this->input->post('days',TRUE);
					$input['teacher_id'] = $this->input->post('teacher',TRUE);
					$input['section_id'] = $this->input->post('section_id');
					
					$this->load->model('M_schedule');
					$result = (object)$this->M_schedule->add_schedule($input);
					if($result->status == 'true')
					{
						$this->session->set_flashdata('system_message','<div class="success">'.$result->msg.'</div>');
						redirect('admin/add_schedule/'.$input['section_id']);
					}else{
						$this->view_data['system_message'] = '<div class="error">'.$result->msg.'</div>';
					}
				}
			}
		}else{
			show_404();
		}
		
	}
		
	function add_subject()
	{
			
		$this->view_data['system_message'] = $this->_msg();	
		$this->view_data['selected_grade_level_id'] = $this->session->flashdata('grade_level_id');
		$this->load->Model(array('M_school_years','M_gperiods'));
		$this->view_data['levels'] = $this->M_levels->get_all_levels_array();
		$this->view_data['academic_year'] = $this->M_school_years->get_all_school_year_array();
		
		if($this->input->post('add'))
		{
			$this->form_validation->set_rules('grade_level_id', 'Grade Level', 'required');
			$this->form_validation->set_rules('code', 'Subject Code', 'required');
			$this->form_validation->set_rules('description', 'Subject Description', 'required');
			$this->form_validation->set_rules('academic_year', 'Academic Year', 'required');
			$this->form_validation->set_rules('subj_uniq_id', 'Unique ID', 'required|is_unique[subjects.subj_uniq_id]');
			$this->form_validation->set_rules('subject_unit', 'Subject Unit', 'required|numeric');
			$this->form_validation->set_message('is_unique', 'Unique Alphanumeric ID Already Taken');

			if($this->form_validation->run() == FALSE)
			{
				$this->view_data['system_message'] = '<div class="error">'.validation_errors().'</div>';
			}else{
				$this->load->model('M_subjects');
				$subject_data['subj_code'] = $this->input->post('code');
				$subject_data['subj_desc'] = $this->input->post('description');
				$subject_data['subj_stat'] = $this->input->post('subj_stat');
				$subject_data['for_academic_year'] = $this->input->post('academic_year');
				$subject_data['grade_level_id'] = $this->input->post('grade_level_id');
				$subject_data['subj_uniq_id'] = $this->input->post('subj_uniq_id');
				$subject_data['subj_units'] = $this->input->post('subject_unit');
				$subject_data['subj_created'] = NOW;
				
				if($this->M_subjects->add_subject($subject_data))
				{
					$this->_msg('s','Successfully added subject with subject code ('.$this->input->post('code').') to database','admin/add_subject');
				}else{
					$this->_msg('e','Unable to add subject with subject code ('.$this->input->post('code').') to database','admin/add_subject');
				}
			}
		}
	}
	
	function add_section()
	{
		$this->load->model('M_employees');
		$this->view_data['system_message'] = $this->session->flashdata('system_message');
		$this->view_data['levels'] = $this->M_levels->get_all_levels_array();
		$this->view_data['teachers'] = $this->M_employees->get_all_employees_array('teacher');
		
		if($this->form_validation->run('grade_level_section') == FALSE)
		{
		
		}
		else
		{	
			$input['section_name'] 	 = $this->input->post('section_name',TRUE);
			$input['grade_level_id'] = 	$this->input->post('section_grade_level',TRUE);
			$input['adviser_id'] 	 = $this->input->post('section_employee_name',TRUE);
			$input['max_load'] 	 = $this->input->post('max_students',TRUE);
			$result = $this->M_sections->add_grade_level_section($input);
			if($result['status'] == 'true')
			{
				if($this->M_employees->update_adviser_status($input['adviser_id']) == TRUE)
				{
					$this->_msg('s',$result['msg'],'admin/add_section');
				}else{
					$this->_msg('n',$result['msg'],'admin/add_section');
				}
			}else
			{
				$this->_msg('e',$result['msg'],'admin/add_section');		
			}
		}
	}
	
	public function searchmonth()
	{	
		if($this->input->post('btnSubmit'))
		{
			if($this->input->post('monthly')!='')
			{
				$year = date('Y',time());
				$this->_msg('s','Search complete.','registrar/birthdays/'.$year.'/'.$this->input->post('monthly'));
			}else{
				$this->_msg('e','Please select a month.','registrar/birthdays');
			}
			
		}else{
			$this->_msg('e','Please select a month.','registrar/birthdays#panel2');
		}
	}
	
	public function birthdays($year ='',$month ='')
	{
		$year = $year == '' ? date('Y',time()) : $year;
		$month = $month == '' ? date('m',time()) : $month;
		
		$this->view_data['system_message'] = $this->_msg();	
		$this->view_data['auth'] = $this->authlink->generate_authlink();
		
		$prefs['template'] = '

		   {table_open}<table class="birthday_calendar" border="1" cellpadding="10" cellspacing="0">{/table_open}

		   {heading_row_start}<tr>{/heading_row_start}
		   {heading_previous_cell}<th><a href="{previous_url}" class="btn"><i class="icon-step-backward"></i></a></th>{/heading_previous_cell}
		   {heading_title_cell}<th colspan="{colspan}">{heading}</th>{/heading_title_cell}
		   {heading_next_cell}<th><a href="{next_url}" class="btn"><i class="icon-step-forward"></i></a></th>{/heading_next_cell}
		   {heading_row_end}</tr>{/heading_row_end}
		   
		   
		   {week_row_start}<tr>{/week_row_start}
		   {week_day_cell}<td class="center"><span class="label">{week_day}</span></td>{/week_day_cell}
		   {week_row_end}</tr>{/week_row_end}

		   {cal_row_start}<tr>{/cal_row_start}
		   {cal_cell_start}<td class="day-format">{/cal_cell_start}

		   {cal_cell_content}{day}<br>{content}{/cal_cell_content}
		   {cal_cell_content_today}<div class="highlight">{day} <br> {content}</div>{/cal_cell_content_today}

		   {cal_cell_no_content}{day}{/cal_cell_no_content}
		   {cal_cell_no_content_today}<div class="highlight">{day}</div>{/cal_cell_no_content_today}

		   {cal_cell_blank}&nbsp;{/cal_cell_blank}

		   {cal_cell_end}</td>{/cal_cell_end}
		   {cal_row_end}</tr>{/cal_row_end}

		   {table_close}</table>{/table_close}
		';
		
		$prefs['start_day']    = 'sunday';
		$prefs['month_type']   ='long';
		$prefs['day_type']     ='long';
		$prefs['show_next_prev']  =TRUE;
		$prefs['next_prev_url'] = base_url().'registrar/birthdays';
		$bdays = $this->M_search->get_birthdays($year,$month);
		$this->load->library('calendar',$prefs);
		$this->view_data['calendar'] = $this->calendar->generate_birthday_calendar($year,$month,$bdays);
		$this->view_data['year'] = $year;	
		$this->view_data['month'] = $month;
	}
	
	public function schedule()
	{
		$this->load->model('M_sections');
		$this->view_data['system_message'] = $this->session->flashdata('system_message');
		/* pagenation */
		$this->load->library('pagination');
		$this->pagnate_config['base_url'] = base_url().'admin/schedule';
		$this->pagnate_config['total_rows'] = $this->M_sections->count_grade_level_section();
		$this->pagnate_config['per_page'] = 15;
		$this->pagnate_config["uri_segment"] = 3;
		$this->pagination->initialize($this->pagnate_config);

		$page = ($this->uri->segment(3)) ? $this->uri->segment(3) : 0;
		$this->view_data['grade_level_section_data'] = $this->M_sections->fetch_grade_level_section($this->pagnate_config["per_page"], $page);
		$this->view_data["links"] = $this->pagination->create_links();
	}

	public function student_id_entry()
	{
		$this->load->library('form_validation');
		
		if($this->input->post('update_student_id'))
		{
			$this->form_validation->set_rules('student_id', 'Enrollment Student ID', 'numeric|trim|htmlspecialchars');
			
			if ($this->form_validation->run() !== FALSE && $this->input->post('student_id') != '')
			{
				$for_e_id  = trim(htmlspecialchars($this->input->post('student_id')));
				if($this->M_for_enrollment_id->update_enrollment_id($for_e_id))
				{
					$this->session->set_flashdata('system_message','<div class="success">Student Enrollment ID saved.</div>');
				}else{
					$this->session->set_flashdata('system_message','<div class="success">Error in saving Student Enrollment ID.</div>');
				}
				redirect('admin/online_settings/onlineenrollment');
			}else{
				if(validation_errors() !== '')
				{
					$this->view_data['system_message'] = $this->_msg('e','Please fix the errors below.');
				}
			}
		}

		$this->view_data['system_message'] = $this->session->flashdata('system_message');
		$this->view_data['for_e_id'] = $this->M_for_enrollment_id->get_enrollment_id();
	}
	
	public function activate_student($authlink = FALSE,$enrollment_id = FALSE)
	{
		if($this->authlink->verify_authlink($authlink) AND is_numeric($enrollment_id))
		{
			$file_needed = $this->M_enrollees->check_needed_files($enrollment_id);
			$file_me[] = '';
			if($file_needed->nationality  == 'Filipino'){
				if($file_needed->form137a ==  NULL ){
					$file_me[] = 'Report Card (F-138) or authentic copy of latest academic record';
				}
				if($file_needed->reccomendationform ==  NULL ){
					$file_me[] = 'Recommendation Letter';
				}
				if($file_needed->birthcertificate ==  NULL ){
					$file_me[] = 'Copy of Birth Certificate';
				}
				if($file_needed->medicalcertificate ==  NULL ){
					$file_me[] = 'Medical Certificate';
				}
				if($file_needed->idpicture2x2 ==  NULL ){
					$file_me[] = '3 copies of 2x2 ID Picture';
				}
			}else{
				if($file_needed->form137a ==  NULL ){
					$file_me[] = 'Report Card (F-138) or authentic copy of latest academic record';
				}
				if($file_needed->reccomendationform ==  NULL ){
					$file_me[] = 'Recommendation Letter';
				}
				if($file_needed->birthcertificate ==  NULL ){
					$file_me[] = 'Copy of Birth Certificate';
				}
				if($file_needed->medicalcertificate ==  NULL ){
					$file_me[] = 'Medical Certificate';
				}
				if($file_needed->idpicture2x2 ==  NULL ){
					$file_me[] = '3 copies of 2x2 ID Picture';
				}
				if($file_needed->passport ==  NULL ){
					$file_me[] = 'Copy of Passport';
				}
				if($file_needed->visa ==  NULL ){
					$file_me[] = 'Copy of Visa';
				}
				if($file_needed->int_icr ==  NULL ){
					$file_me[] = 'Copy of ACR-icard';
				}
				if($file_needed->int_specialpermit ==  NULL ){
					$file_me[] = 'Special Study Permit';
				}
			}

			$activate = $this->M_enrollees->registrar_activate_student($enrollment_id);
			if($activate->status == TRUE)
			{
				if(!empty($file_me))
				{
					$enroll_data['with_weaver'] = 'yes';
					$this->db->where('e_id', $enrollment_id);
					$this->db->update('enrollments', $enroll_data);
				}

				$this->load->model('M_for_enrollment_id');
				$this->load->library('idno_creator');
				$generated_studentid = $this->idno_creator->generate_id();
				$generated_id = $this->M_for_enrollment_id->check_id_generation($enrollment_id);

				if($generated_id == FALSE){
					//update student number
					$data['e_student_id'] = $generated_studentid;
					$data['id_generated'] = 1;

					$this->db->where('e_id', $enrollment_id);
					$this->db->update('enrollments', $data); 
				}else{
					$sql = "SELECT for_e_id
							FROM for_enrollment_id 
							LIMIT 1";
					$query = $this->db->query($sql);
					if( $query->num_rows() >=1 ){
						$r = $query->row();
						$v = $r->for_e_id;
						$tempv = $v-1;
						$data_for_id['for_e_id'] = $tempv;
						$this->db->truncate('for_enrollment_id');
						$this->db->insert('for_enrollment_id', $data_for_id);
					}
				}

				$cred = $this->M_enrollees->registrar_create_student_login_credentials($enrollment_id);
				if($cred->stat == TRUE)	{
					$this->_send_student_username_password($cred->fullname,$cred->email,$cred->username,$cred->password);
					sleep(3);
					
					//$message = $cred->log;
					$message  = ' System has successfully created login details for: '.ucwords(strtolower($cred->fullname)).' ';
					$message .= ' with username: '.$cred->username.' and password: '.$cred->password.'. ';
					$message .= ' An email was also sent to: '.$cred->email.', containing the username and password.';

					$this->_msg('s',$message,'profile/student/'.$enrollment_id);
				}else{
					$this->_msg('e',$cred->log,'profile/student/'.$enrollment_id);
				}
			}else{
				log_message('error', 'Registrar unable to enroll student with enrollment_id '.$enrollment_id.'.');
				$this->_msg('e',$activate->message,'profile/student/'.$enrollment_id);
			}
		}else{
			$this->_msg('e','Invalid URL Link.','profile/student/'.$enrollment_id);
		}
	}
	
	/** Reset Students Password
	 *	Show List and search of officcially enrolled students
	 *  SYLVER | 8/7/2014
	 * from small world
	 */
	public function reset_student_password($where="all")
	{
		$this->load->model('M_search','ms');
		$this->view_data['system_message'] = $this->_msg();

		//create a-z links
		$a_z = range('a','z');
		//add all to first 
		array_unshift($a_z, 'all');
		
		$where = in_array($where,$a_z) ? $where : 'all';
		$count_total = $this->ms->count_approved_enrolled($where);
		if($this->input->post('search'))
		{
			$student = $this->input->post('student_search_data',TRUE);
			$f_student = strpos($student,'-') > 0 ? explode('-',$student) : FALSE;
			if($f_student){
				$this->view_data['students'] = $this->ms->search_approved_enrolled(FALSE,$f_student[0]);
				$this->view_data['links'] = NULL;
			}else{
				redirect('registrar/reset_student_password');
			}
			
		}else{
			$this->load->library('pagination');
			$this->pagnate_config['base_url'] = base_url().'registrar/reset_student_password/'.$where;
			$this->pagnate_config['per_page'] = 10;
			$this->pagnate_config["uri_segment"] = 4;
			$this->pagnate_config['total_rows'] = $count_total;
			
			$this->pagination->initialize($this->pagnate_config);
			
			$page = ($this->uri->segment(4)) ? $this->uri->segment(4) : 0;
			$this->view_data['students'] = 	$this->ms->approved_enrolled($this->pagnate_config['per_page'],$page,$where);

			$this->view_data['links'] = $this->pagination->create_links();
			
		}
		
		$this->view_data['total'] = $count_total;
		$this->view_data['a_z'] = $a_z;
		$this->view_data['active'] = $where;
	}
	
	/** Process Reset Students Password
	 *	@id - enrollment id, if id LAHAT it means update all students
	 *  SYLVER | 8/7/2014
	 */
	public function process_reset_student_password($id = FALSE)
	{
		if($id !== FALSE){
			// LOAD MODELS
			$this->load->model('M_enrollees','M_search');

			/* UPDATE ALL STUDENTS PASSWORD */
			if($id === "LAHAT"){

				set_time_limit(0);

				$all = $this->M_search->approved_enrolled(0,0, 'all', true);
				
				if($all){
					$ctr = 0;
					foreach ($all as $key => $stud) {
						$rs = $this->_reset_student_password($stud->enrollment_id);
						if($rs->status){
							$ctr++;
						}
					}

					if($ctr > 0){

						$this->_msg('s','All student password was successfully updated to their student ID.', 'registrar/reset_student_password');
					}else{
						$this->_msg('e','No students was updated during the process.', 'registrar/reset_student_password');
					}
				}

			}else{

				$rs = $this->_reset_student_password($id);
				if($rs->status){
					$this->_msg('s','Student password was successfully updated to "'. $rs->password .'" (without the qoutes).', 'registrar/reset_student_password');
				}else{
					$this->_msg('e','Something went wrong, process not successfull. Please try again.', 'registrar/reset_student_password');
				}
			}

		}else{
			show_404();
		}
	}
	
	/** Reset Student Password
	 * @id Enrollment ID
	 * SLY | 8/7/2014
	 */
	private function _reset_student_password($id = false)
	{
		$ret['status'] = false;
		$ret['data'] = "";
		$ret['password'] = "";
		$ret = (object)$ret;

		$this->load->library('email');

		if($id){

			/* GET STUDENT USER ID AND PROFILE */
			unset($get);
			$get['fields'] = array(
				'profiles.profile_id',
				'profiles.user_id',
				'users.username',
				'enrollments.e_student_id',
				'profiles.email',
				"concat(profiles.firstname,' ',profiles.middlename,' ',profiles.lastname) as fullname",
				);
			$get['where']['enrollments.e_id'] = $id;
			$get['single'] = true;
			$get['join'][] = array(
					'table' => 'profiles',
					'on' => 'enrollments.e_profile_id = profiles.profile_id',
					'type' => 'left'
				);
			$get['join'][] = array(
					'table' => 'users',
					'on' => 'profiles.user_id = users.id',
					'type' => 'left'
				);
			
			$enrollment = $this->M_enrollees->get_record(false, $get);
			// vd($enrollment);
			if($enrollment){
				
				$this->load->model('M_users');
				if($enrollment->user_id!=0)
				{
					$rs = $this->M_users->udpate_users_passwod($enrollment->user_id, $enrollment->e_student_id);
				}else{
					$rs = $this->M_users->insert_users_passwod($enrollment->user_id, $enrollment->e_student_id, $enrollment->profile_id);
				}

				if($rs){
					$ret->status = true;
					$ret->password = $enrollment->e_student_id;
					$ret->data = $enrollment;

					/* SEND PASSWORD TO EMAIL  */
					$this->_send_student_username_password($enrollment->fullname,$enrollment->email,$enrollment->username,$enrollment->e_student_id,2);

					return $ret;
				}
			}
		}

		return $ret;
	}
	
	private function _send_student_username_password($fullname,$email,$username,$password, $layout = 1)
	{
		$school_name = ucwords($this->school_name);
		$school_name_title = $this->_accronymizer($this->school_name).'@DONOTREPLY.com';
		$student_page_link = $this->config->item('student_url');
		
		if($this->school_tag_name == FALSE)
		{
			$tagname = 'part of '.$school_name;
		}else{
			$tagname = 'a '.strtoupper($this->school_tag_name);
		}
		
		$data['school_name'] = $school_name;
		$data['acc'] = $school_name_title;
		$data['link'] = $student_page_link;
		$data['tagname'] = $tagname;
		$data['name'] = ucwords($fullname);
		$data['username'] = $username;
		$data['password'] = $password;

		$message = "";
		
		switch ($layout) {
			case 1:
				$message = $this->load->view('email_templates/registrar_send_student_login_info',$data,TRUE);
				break;
			case 2:
				$message = $this->load->view('email_templates/registrar_send_student_login_info2',$data,TRUE);
				break;
		}
		
		$this->load->library('email');
		$this->email->initialize(array( 
		   'mailtype' => 'html', 
		)); 
		$this->email->from($school_name_title,$school_name);
		$this->email->to($email);
		$this->email->subject('Thank You. Here are you account credentials.');
		$this->email->message($message);
		$this->email->send();
	}
	
	/*
	Early Enrollment
	*/
	public function early_enrollment()
	{
		
		$this->load->model('M_levels','ml');
		$this->load->model('M_search','ms');
		$this->load->model('M_school_years');
		if($this->M_school_years->open_reg_sy())
		{
			$this->view_data['gls'] = $this->ml->get_all_levels();
			$this->view_data['students'] = $this->ms->default_masterlist('default');
			$this->view_data['enrolled'] = $this->ms->search_enrolled();
			$this->view_data['hash'] = $this->hs->encrypt(time());
		}
	}
	
	public function early_enrollment_me($hash)
	{
		$this->load->model(array('M_levels','M_enrollees','M_school_years','M_enrollment'));
		
		$x = $this->hs->decrypt($hash);
		$e_id = $x[0];
		
		$p = $this->M_enrollees->get_enrollee_prof($e_id);
		$l = $this->M_levels->get_lesser_level($p->level_id);

		$rs = $this->M_enrollment->early_enroll($e_id, $l->level_id, $p->profile_id);
		if($rs)
		{
			$this->_msg('s','Student successfully enrolled.', 'registrar/early_enrollment');
		}else{
			$this->_msg('e','Something went wrong. Process not successfull. Please try again.', 'registrar/early_enrollment');
		}
	}
	/*
	private function _accronymizer($string = FALSE)
	{
		if($string !== FALSE)
		{
			$clean_string = htmlspecialchars(strip_tags($string));
			$number_of_words = str_word_count($clean_string,1);
			function acc($x)
			{
				if(strlen($x) > 1)
				{
					return $x[0];
				}
			}
			$accronym = array_map("acc",$number_of_words);
			return strtoupper(implode('',$accronym));
		}else{
			return NULL;
		}
	}*/
}

?>
